package xian.woniuxy.be.web;

import org.apache.shiro.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import xian.woniuxy.be.entity.Orderdetail;
import xian.woniuxy.be.entity.Orders;
import xian.woniuxy.be.entity.ResultVO;
import xian.woniuxy.be.service.IOrderdetailService;
import xian.woniuxy.be.service.IOrdersService;

import java.util.List;

/**
 * @author Gong
 * @time 2022/01/09 01:02:20
 */
@RestController
public class OrderdetailController {

    @Autowired
    private IOrderdetailService orderdetailService;

    @PostMapping("orderdetail/delete")
    public ResultVO delete(@RequestBody String orderdetailId){
        if (!StringUtils.hasText(orderdetailId)){
            throw new RuntimeException("客户ID为空");
        }
        orderdetailService.delete(Integer.valueOf(orderdetailId));
        return ResultVO.success("删除成功");
    }

    @PostMapping("orderdetail/update")
    public ResultVO update(@RequestBody Orderdetail orderdetail){
        orderdetailService.update(orderdetail);
        return ResultVO.success("修改成功");
    }

    @PostMapping("orderdetail/findOne")
    public ResultVO findOne(@RequestBody String orderdetailId){
        if (!StringUtils.hasText(orderdetailId)){
            throw new RuntimeException("订单ID为空");
        }
        List<Orderdetail> list = orderdetailService.findOne(Integer.valueOf(orderdetailId));
        return ResultVO.success(list);
    }

}
